using System;

namespace UnitTesting.Fixturing
{
	abstract class MockActivatorBase : IActivator
	{
		public object Create(ActivatorParams activatorParams)
		{
			Ensure.IsNotNull(() => activatorParams.TargetType);
			Ensure.IsNotNull(() => activatorParams.Arguments);
			return activatorParams.TargetType.IsSealed
			       	? CreateSealedInstance(activatorParams.TargetType, activatorParams.Arguments)
			       	: CreateNotSealedInstance(activatorParams.TargetType, activatorParams.Arguments);
		}

		static object CreateSealedInstance(Type type, object[] arguments)
		{
			return DefaultActivator.Instance.Create(new ActivatorParams {TargetType = type, Arguments = arguments});
		}

		object CreateNotSealedInstance(Type type, object[] arguments)
		{
			return CreateInstance(type, arguments);
		}

		protected abstract object CreateInstance(Type type, object[] arguments);
	}
}